package com.jmodusoperandi.utils.model.schema;

import org.hibernate.cfg.AnnotationConfiguration;

//http://docs.jboss.org/hibernate/core/3.3/reference/en/html/session-configuration.html

public class DDLGenerator {

	/**
	 * @param args
	 */
	
	public static void main(String[] args) {
		
		//Existen varias formas de configurar el tema
		AnnotationConfiguration cfg = new AnnotationConfiguration();
		//Configuraci�n de las clases que se a�adira al modelo
	    //cfg	.addPackage("com.arquitecturalogica.pedidos.model");
//	    cfg.addAnnotatedClass(com.jmodusoperandi.orders.model.Client.class);
//	    cfg.addAnnotatedClass(com.jmodusoperandi.orders.model.Order.class);
		//Configuraci�n del datasource
	    //esto para el caso en el que queramos utilizar el pool de hibernate. No apto entorno PROD
	    cfg	.setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver")
	    	.setProperty("hibernate.connection.url", "jdbc:hsqldb:hsql://127.0.0.1/xdb")
	    	.setProperty("hibernate.connection.username", "sa")
	    	.setProperty("hibernate.connection.password", "")
	    	.setProperty("hibernate.connection.pool_size", "5");
	    
	    //hibernate dialect
	    cfg	.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
	    
	    //generaci�n del schema
	    cfg	.setProperty("hibernate.hbm2ddl.auto", "create-drop");
	    
	    //ver sql generado en el camino hibernate.show_sql
	    cfg	.setProperty("hibernate.show_sql", "true");
	    
	    //action
	    cfg.buildSessionFactory().openSession();
	    
//	    .setProperty("hibernate.dialect", "org.hibernate.dialect.org.hibernate.dialect.HSQLDialect")
//	    .setProperty("hibernate.connection.datasource", "java:comp/<env/jdbc/test")
//	    .setProperty("hibernate.order_updates", "true");

	}


/*
 * Hibernate Simple connection Properties	
 */

/*	hibernate.connection.driver_class		JDBC driver class
	hibernate.connection.url				JDBC URL
	hibernate.connection.username			database user
	hibernate.connection.password			database user password
	hibernate.connection.pool_size			maximum number of pooled connections
*/	

/*
 * Hibernate C3p0 conf properties
 */

/*	hibernate.connection.driver_class = org.postgresql.Driver
	hibernate.connection.url = jdbc:postgresql://localhost/mydatabase
	hibernate.connection.username = myuser
	hibernate.connection.password = secret
	hibernate.c3p0.min_size=5
	hibernate.c3p0.max_size=20
	hibernate.c3p0.timeout=1800
	hibernate.c3p0.max_statements=50
	hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
*/	

/*
 * Optional parameters
 */
	
/*
	hibernate.dialect	 
					The classname of a Hibernate org.hibernate.dialect.Dialect which allows Hibernate to generate SQL optimized for a particular relational database.
					e.g. full.classname.of.Dialect

					In most cases Hibernate will actually be able to choose the correct org.hibernate.dialect.Dialect implementation based on the JDBC metadata returned by the JDBC driver.

	hibernate.show_sql	 
					Write all SQL statements to console. This is an alternative to setting the log category org.hibernate.SQL to debug.
					e.g. true | false

	hibernate.format_sql	 
					Pretty print the SQL in the log and console. e.g. true | false
	hibernate.default_schema	 
					Qualify unqualified table names with the given schema/tablespace in generated SQL. e.g. SCHEMA_NAME
	hibernate.default_catalog	 
					Qualifies unqualified table names with the given catalog in generated SQL. e.g. CATALOG_NAME
	hibernate.session_factory_name	 
					The org.hibernate.SessionFactory will be automatically bound to this name in JNDI after it has been created.
					e.g. jndi/composite/name

	hibernate.max_fetch_depth	 
					Sets a maximum "depth" for the outer join fetch tree for single-ended associations (one-to-one, many-to-one). A 0 disables default outer join fetching.
					e.g. recommended values between 0 and 3

	hibernate.default_batch_fetch_size	 
					Sets a default size for Hibernate batch fetching of associations. e.g. recommended values 4, 8, 16
	hibernate.default_entity_mode	 
					Sets a default mode for entity representation for all sessions opened from this SessionFactory
					dynamic-map, dom4j, pojo

	hibernate.order_updates	 
					Forces Hibernate to order SQL updates by the primary key value of the items being updated. This will result in fewer transaction deadlocks in highly concurrent systems. e.g. true | false
	hibernate.generate_statistics	 
					If enabled, Hibernate will collect statistics useful for performance tuning. e.g. true | false
	hibernate.use_identifier_rollback	 
					If enabled, generated identifier properties will be reset to default values when objects are deleted. e.g. true | false
	hibernate.use_sql_comments	 
					If turned on, Hibernate will generate comments inside the SQL, for easier debugging, defaults to false.
					e.g. true | false	
*/	
	
	
/*
 * Hibernate datasource properties	
 */
	
/*	hibernate.connection.datasource	datasource JNDI name
	hibernate.jndi.url	URL of the JNDI provider (optional)
	hibernate.jndi.class	class of the JNDI InitialContextFactory (optional)
	hibernate.connection.username	database user (optional)
	hibernate.connection.password	database user password (optional)
*/	
	
/*
 * Hibernate SQL dialects	
 */
	
/*	DB2						org.hibernate.dialect.DB2Dialect
	DB2 AS/400				org.hibernate.dialect.DB2400Dialect
	DB2 OS390				org.hibernate.dialect.DB2390Dialect
	PostgreSQL				org.hibernate.dialect.PostgreSQLDialect
	MySQL					org.hibernate.dialect.MySQLDialect
	MySQL with InnoDB		org.hibernate.dialect.MySQLInnoDBDialect
	MySQL with MyISAM		org.hibernate.dialect.MySQLMyISAMDialect
	Oracle (any version)	org.hibernate.dialect.OracleDialect
	Oracle 9i				org.hibernate.dialect.Oracle9iDialect
	Oracle 10g				org.hibernate.dialect.Oracle10gDialect
	Sybase					org.hibernate.dialect.SybaseDialect
	Sybase Anywhere			org.hibernate.dialect.SybaseAnywhereDialect
	Microsoft SQL Server	org.hibernate.dialect.SQLServerDialect
	SAP DB					org.hibernate.dialect.SAPDBDialect
	Informix				org.hibernate.dialect.InformixDialect
	HypersonicSQL			org.hibernate.dialect.HSQLDialect
	Ingres					org.hibernate.dialect.IngresDialect
	Progress				org.hibernate.dialect.ProgressDialect
	Mckoi SQL				org.hibernate.dialect.MckoiDialect
	Interbase				org.hibernate.dialect.InterbaseDialect
	Pointbase				org.hibernate.dialect.PointbaseDialect
	FrontBase				org.hibernate.dialect.FrontbaseDialect
	Firebird				org.hibernate.dialect.FirebirdDialect
*/	

/*
 * Naming Strategy	
 */
	
//	3.6. Implementing a NamingStrategy
//
//	The interface org.hibernate.cfg.NamingStrategy allows you to specify a "naming standard" for database objects and schema elements.
//
//	You can provide rules for automatically generating database identifiers from Java identifiers or for processing "logical" column and table names given in the mapping file into "physical" table and column names. This feature helps reduce the verbosity of the mapping document, eliminating repetitive noise (TBL_ prefixes, for example). The default strategy used by Hibernate is quite minimal.
//
//	You can specify a different strategy by calling Configuration.setNamingStrategy() before adding mappings:
//
//	SessionFactory sf = new Configuration()
//	    .setNamingStrategy(ImprovedNamingStrategy.INSTANCE)
//	    .addFile("Item.hbm.xml")
//	    .addFile("Bid.hbm.xml")
//	    .buildSessionFactory();
//	org.hibernate.cfg.ImprovedNamingStrategy is a built-in strategy that might be a useful starting point for some applications.	
	
}
